home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Search.aspx.cs492
< prev
next >
Wrap
Text File
|
2008-05-06
|
19KB
|
457 lines
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
/// <summary>
/// Summary description for Search.
/// </summary>
public partial class Search : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputImage imageSubmit;
protected System.Web.UI.HtmlControls.HtmlTableRow trMoviesOnly;
private Settings guideParams;
private static string showSearchResults;
private static int TimelineRepeat;
protected void Page_Load(object sender, System.EventArgs e)
{
//Code to prevent Guest users from accessing the Search page directly by URL
if (!Convert.ToBoolean((string)Session["NotGuestUser"]))
{
string hostAddress = string.Empty;
string Url =
Request.Url.ToString().Replace(Request.Url.Scheme + Uri.SchemeDelimiter + Request.Url.Authority,
Request.Url.Scheme + Uri.SchemeDelimiter + Request.Headers["Host"]);
string redirectUrl = Url.ToLower().Replace("search.aspx", "guide.aspx");
Logger.Info(" ");
Logger.Info(" ");
Logger.Info("Guest user trying to access the search page......");
Logger.Info("Pulling User IP Info...");
if (Request.UserHostAddress.Substring(0, 1) == ":")
{
Logger.Info("IP V6 Detected");
hostAddress = GetIP4Address();
Logger.Info("IP6 Address: " + Request.UserHostAddress);
Logger.Info("IP4 Address: " + hostAddress);
Logger.Info(" ");
}
else
{
Logger.Info("IP V4 Detected");
hostAddress = Request.UserHostAddress;
Logger.Info("IP4 Address: " + hostAddress);
Logger.Info(" ");
}
Logger.Info("Redirecting user to the guide");
Logger.Info(" ");
Logger.Info(" ");
Response.Redirect(redirectUrl, true);
}
Session["GuideStartTime"] = null;
if (!IsPostBack)
{
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
guideParams = Global.Settings;
HttpCookie cookie = Request.Cookies["showSearchResults"];
showSearchResults = cookie != null ? cookie.Value : "tree";
//If the user has opted to use the TreeView search results allow the user to see the sort order
//options otherwise do not show them
if (showSearchResults == "tree")
{
treeViewSort.Visible = true;
//If the user has ExtendedEWA then dynamicaly add a button for Star Rating sort
if (ExtendedEWA.Initialize())
{
ListItem starRating = new ListItem();
starRating.Text = "Star Rating";
starRating.Value = "star";
srtOrder.Items.Add(starRating);
ListItem originalAirDate = new ListItem();
originalAirDate.Text = "Original Air Date (oad)";
originalAirDate.Value = "originalAirDate";
srtOrder.Items.Add(originalAirDate);
}
//Set the selected search order to whatever was used the last time
cookie = Request.Cookies["SearchSortOrder"];
srtOrder.SelectedValue = cookie != null ? cookie.Value : "title";
}
else
{
treeViewSort.Visible = false;
}
Schedule scheduleHelper = Global.Schedule;
IList listingsForPeriod;
listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(DateTime.Now, DateTime.Now);
foreach (Channel channel in listingsForPeriod)
{
listChannels.Items.Add(new ListItem(channel.getName(), channel.channelNumber.ToString()));
}
Global.FillGenreList(genreList);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void hlSubmit_Click(object sender, EventArgs e)
{
if ((searchPhrase.Value.Length > 0) ||
((searchPhrase.Value.Length == 0) &&
((genreList.SelectedValue != null && genreList.SelectedValue != "") ||
(startDate.PostedDate != null && startDate.PostedDate != "") ||
(startTime.PostedTime != null && startTime.PostedTime != "") ||
(endDate.PostedDate != null && endDate.PostedDate != "") ||
(endTime.PostedTime != null && endTime.PostedTime != "") ||
(textMinLength.Value != null && textMinLength.Value != "") ||
(textMaxLength.Value != null && textMaxLength.Value != "") ||
(listChannels.SelectedValue != null && listChannels.SelectedValue != ""))))
{
//Store the selected sort order in the cookie for the next search
HttpCookie cookie = new HttpCookie("SearchSortOrder", srtOrder.SelectedValue);
cookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(cookie);
//Since we are using server.transfer the updated cookie is not availble to the results page.
//We must use server.transfer to easily pass the selcted options and search text to the results page
//for processing.
Session["SearchResultsOption"] = srtOrder.SelectedValue;
//Transfer user to Search Results page for viewing
Server.Transfer("SearchResults.aspx");
}
}
protected void hlReset_Click(object sender, EventArgs e)
{
//Back to search page to reset values
Response.Redirect("Search.aspx");
}
protected void loadSearch(object sender, EventArgs e)
{
if (savedSearchList.SelectedIndex != 0)
{
SavedSearchUtils searchUtils = new SavedSearchUtils();
SavedSearch search = searchUtils.loadSearch(savedSearchList.SelectedValue);
autoSearchInclude.Checked = search.isAutoShowSearch();
autoRecordInclude.Checked = search.isAutoRecordSearch();
checkTitle.Checked = search.getSearchTitle();
checkDescription.Checked = search.getSearchDescription();
checkSubTitle.Checked = search.getSearchSubTitle();
searchPhrase.Value = search.getSearchPhrase();
caseSensitive.Checked = search.isCaseSensitiveSearch();
textMinLength.Value = search.getSearchLengthMin();
textMaxLength.Value = search.getSearchLengthMax();
if (search.getTreeViewSortOrder() != "")
{
srtOrder.SelectedValue = search.getTreeViewSortOrder();
}
if (search.getSearchStartDate() != null && search.getSearchStartDate() != "" && search.getSearchStartDate() != "1/1/0001")
{
startDate.SelectedDate = searchUtils.toDate(search.getSearchStartDate());
}
else
{
startDate.Clear();
}
if (search.getSearchStartTime() != null && search.getSearchStartTime() != "" && (search.getSearchStartDate() != "1/1/0001" && search.getSearchStartTime() != "12:00 AM"))
{
startTime.SelectedTime = searchUtils.toDate(search.getSearchStartTime());
}
else
{
startTime.Clear();
}
if (search.getSearchEndDate() != null && search.getSearchEndDate() != "" && search.getSearchEndDate() != "1/1/0001")
{
endDate.SelectedDate = searchUtils.toDate(search.getSearchEndDate());
}
else
{
endDate.Clear();
}
if (search.getSearchEndTime() != null && search.getSearchEndTime() != "" && (search.getSearchEndDate() != "1/1/0001" && search.getSearchEndTime() != "12:00 AM"))
{
endTime.SelectedTime = searchUtils.toDate(search.getSearchEndTime());
}
else
{
endTime.Clear();
}
genreList.SelectedIndex = -1;
listChannels.SelectedIndex = -1;
foreach (string genre in search.getSearchGenres())
{
try
{
genreList.Items.FindByValue(genre).Selected = true;
}
catch
{
}
}
foreach (string channel in search.getSearchChannels())
{
try
{
listChannels.Items.FindByValue(channel).Selected = true;
}
catch
{
}
}
//If our saved search does not match the current search version value then we need to update it so that it has all the new default values
guideParams = Global.Settings;
if (search.getSearchVersion() != guideParams.CurrentSearchVersion)
{
updateSavedSearch_Click(null, null);
}
}
else
{
newSearchName.Value = "";
searchPhrase.Value = "";
foreach (ListItem item in genreList.Items)
{
item.Selected = false;
}
foreach (ListItem item in listChannels.Items)
{
item.Selected = false;
}
}
}
protected void deleteSavedSearch_Click(object sender, EventArgs e)
{
if (savedSearchList.SelectedIndex != 0)
{
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.deleteSearch(savedSearchList.SelectedValue);
savedSearchList.Items.Clear();
searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
savedSearchList.SelectedIndex = 0;
newSearchName.Value = "";
searchPhrase.Value = "";
foreach (ListItem item in genreList.Items)
{
item.Selected = false;
}
foreach (ListItem item in listChannels.Items)
{
item.Selected = false;
}
}
}
protected void saveSearch_Click(object sender, EventArgs e)
{
if (newSearchName.Value.Length > 0)
{
SavedSearch search = new SavedSearch();
search.setSearchName(newSearchName.Value);
search.setautoShowSearch(autoSearchInclude.Checked);
search.setautoRecordSearch(autoRecordInclude.Checked);
search.setSearchTitle(checkTitle.Checked);
search.setSearchSubTitle(checkSubTitle.Checked);
search.setSearchDescription(checkDescription.Checked);
search.setSearchPhrase(searchPhrase.Value);
search.setSearchCaseSensitive(caseSensitive.Checked);
foreach(ListItem item in genreList.Items)
{
if (item.Selected)
{
search.addSearchGenres(item.Value);
}
}
if (treeViewSort.Visible)
{
search.setTreeviewSortOrder(srtOrder.SelectedValue);
}
search.setSearchLengthMin(textMinLength.Value);
search.setSearchLengthMax(textMaxLength.Value);
foreach (ListItem item in listChannels.Items)
{
if (item.Selected)
{
search.addSearchChannels(item.Value);
}
}
if (searchPhrase.Value.Length == 0 && genreList.SelectedIndex == -1 && listChannels.SelectedIndex == -1 &&
textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
{
search.setSearchPhrase(newSearchName.Value);
searchPhrase.Value = newSearchName.Value;
}
if (startDate.PostedDate != "")
{
search.setSearchStartDate(startDate.PostedDate);
}
else
{
search.setSearchStartDate(null);
}
search.setSearchStartTime(startTime.PostedTime);
if (endDate.PostedDate != "")
{
search.setSearchEndDate(endDate.PostedDate);
}
else
{
search.setSearchEndDate(null);
}
search.setSearchEndTime(endTime.PostedTime);
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.deleteSearch(newSearchName.Value);
searchUtil.writeSearch(search);
savedSearchList.Items.Clear();
searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
savedSearchList.SelectedValue = newSearchName.Value;
newSearchName.Value = string.Empty;
}
}
protected void updateSavedSearch_Click(object sender, EventArgs e)
{
SavedSearch search = new SavedSearch();
guideParams = Global.Settings;
search.setSearchName(savedSearchList.SelectedValue);
search.setSearchVersion(guideParams.CurrentSearchVersion);
search.setautoShowSearch(autoSearchInclude.Checked);
search.setautoRecordSearch(autoRecordInclude.Checked);
search.setSearchTitle(checkTitle.Checked);
search.setSearchSubTitle(checkSubTitle.Checked);
search.setSearchDescription(checkDescription.Checked);
search.setSearchPhrase(searchPhrase.Value);
search.setSearchCaseSensitive(caseSensitive.Checked);
foreach (ListItem item in genreList.Items)
{
if (item.Selected)
{
search.addSearchGenres(item.Value);
}
}
if (treeViewSort.Visible)
{
search.setTreeviewSortOrder(srtOrder.SelectedValue);
}
search.setSearchLengthMin(textMinLength.Value);
search.setSearchLengthMax(textMaxLength.Value);
foreach (ListItem item in listChannels.Items)
{
if (item.Selected)
{
search.addSearchChannels(item.Value);
}
}
if (searchPhrase.Value.Length == 0 && genreList.Items.Count == 0 && listChannels.Items.Count == 0 &&
textMaxLength.Value.Length == 0 && textMinLength.Value.Length == 0)
{
search.setSearchPhrase(newSearchName.Value);
}
if (startDate.PostedDate != "")
{
search.setSearchStartDate(startDate.PostedDate);
}
else
{
search.setSearchStartDate(null);
}
search.setSearchStartTime(startTime.PostedTime);
if (endDate.PostedDate != "")
{
search.setSearchEndDate(endDate.PostedDate);
}
else
{
search.setSearchEndDate(null);
}
search.setSearchEndTime(endTime.PostedTime);
SavedSearchUtils searchUtil = new SavedSearchUtils();
searchUtil.deleteSearch(savedSearchList.SelectedValue);
searchUtil.writeSearch(search);
}
protected void savedSearchFilter_SelectedIndexChanged(object sender, EventArgs e)
{
SavedSearchUtils searchUtil = new SavedSearchUtils();
savedSearchList.Items.Clear();
searchUtil.loadSearchList(savedSearchList, savedSearchFilter.SelectedValue);
}
public string GetIP4Address()
{
string strIP4Address = String.Empty;
foreach (IPAddress objIP in Dns.GetHostAddresses(Dns.GetHostName()))
{
if (objIP.AddressFamily.ToString() == "InterNetwork")
{
strIP4Address = objIP.ToString();
break;
}
}
return strIP4Address;
}
}
}